<template>
  <div>
    <pre class="code language-python line-numbers" v-html="html"></pre>
    <el-button ref="btnCopy" type="info" style="position: absolute; top: 20px; right: 10px;">复制</el-button>
  </div>
</template>

<script>

import Prism from 'prismjs';
import 'prismjs/components/prism-python';
import FpCodeMixin from './FpCodeMixin';

export default {
  name: "FpCodePython",
  mixins: [FpCodeMixin],
  computed: {
    html() {
      return Prism.highlight(this.code(), Prism.languages.python, 'python');
    }
  },
  methods: {
    code() {
      let c1 = this.json() || '    # 暂未指定任何动态参数\n'
      let c = `from fastposter import Client

# 如需进一步了解，请参考开发文档 https://cloud.fastposter.net/doc/sdk/

# 1.创建海报客户端对象
client = Client("${this.token}", "${this.apiUrl}")

# 2.准备海报参数（从实际业务系统中获取）
params = ${c1}

# 3.生成海报并保存(提供图片流、二进制、base64等多种方式)
client.buildPoster("${this.posterId || '未生成'}", params=params).save("demo.png")`
      return c
    }
  }
}
</script>

<style scoped>

.code {
  text-align: left;
  overflow: auto;
  user-select: text;
  cursor: text;
  height: 500px;
  font-size: 13px;
}

</style>